package com.taotao.manage.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.constant.SystemConstant;
import com.taotao.common.dto.TreeNode;
import com.taotao.entity.ItemCat;
import com.taotao.manage.service.ItemCatService;

/**  
 * @Title：ItemCatController.java   
 * @Description：
 * @Author：张朝阳
 * @Date：2019年7月4日 下午10:34:33   
 */
@Controller
@RequestMapping("itemCat")
public class ItemCatController {
	
	@Autowired
	private ItemCatService itemCatService;
	
	@RequestMapping("/list")
	@ResponseBody
	public List<TreeNode> getItemCatList(@RequestParam(value="id",defaultValue="0")long parentId) {
		
		List<ItemCat> itemCatList = itemCatService.getItemCatList(parentId);
		
		List<TreeNode> list = new ArrayList<>();
		for (ItemCat itemCat : itemCatList) {
			TreeNode treeNode = new TreeNode();
			treeNode.setId(itemCat.getId());
			treeNode.setText(itemCat.getName());
			treeNode.setState(SystemConstant.NodeStatus.getNameByCode(itemCat.getStatus()));
			list.add(treeNode);
		}
		return list;
	}}
